import type { MatchPreviewData } from '../components/historyRecord/types.js';
import { gameAssetManager } from '@/LcuApi/gameAsset';
import { getRelativeTime } from '@/utils'

// 格式化历史战绩
export async function getMatchData(data) {
  const participant = data?.participants?.[0]
  const stats = participant?.stats

  const matchData: MatchPreviewData = {
    gameId: data.gameId,
    timestamp: data.gameCreation,
    time: getRelativeTime(data.gameCreation), // 相对时间
    mapId: data.mapId, // 地图
    championId: participant?.championId, // 英雄
    kills: stats?.kills, // 击杀
    deaths: stats?.deaths, // 死亡
    assists: stats?.assists, // 助攻
    win: stats?.win,
    queueInfo: await gameAssetManager.getGameQueueInfo(data.queueId),
  }

  return matchData
}
